import type { Options } from '@mikro-orm/core';
import { defineConfig } from '@mikro-orm/mysql';
import { Logger } from '@nestjs/common';
import { config as environmentConfig } from 'dotenv';
import dotEnvExpand from 'dotenv-expand';
import { baseOptions } from './orm.config';

const logger = new Logger("MikroORM");

const environment = environmentConfig({
  path: `${process.cwd()}/env/.env.${process.env.NODE_ENV}`,
});

dotEnvExpand.expand(environment);

logger.log(`🛠️ Using env ${process.cwd()}/env/.env.${process.env.NODE_ENV}\n`);


const config: Options = defineConfig({
  ...baseOptions,
  dbName: process.env.DB_DATABASE,
  password: process.env.DB_PASSWORD,
  port: process.env.DB_PORT,
  user: process.env.DB_USERNAME,
  host: process.env.DB_HOST,
});

export default config;